Fix monitoring: count retry attempts correctly and use K/M/B token units#187
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Description
src/utils/usageStats.jsto acceptsuccessCount/failedCount, addtoSafeCount(), and updaterecord()to aggregate per-day and per-modelrequests,success, andfailedusing those counts.recordUsageAttemptFailure(req, ...)helper and wire it into the retry flow so failed retry attempts are accumulated onreq.apiUsageMetricsinstead of being mis-counted as successes.onAttemptFailurecallback insrc/server/handlers/common/retry.jsso callers can record failed attempts, and addonAttemptFailuretocreateRetryOptionsinsrc/server/handlers/openai.js,src/server/handlers/claude.js,src/server/handlers/gemini.jsandsrc/server/handlers/geminicli.jsto invokerecordUsageAttemptFailure(req, { model })on retry failures.src/server/index.jsto passsuccessCountandfailedCountintousageStats.record()based onreq.apiUsageMetrics.failedAttemptsand the finalres.statusCodeso totals reflect conversation attempts (e.g. 3 failures + 1 success → total 4).public/js/monitor.jsto useformatTokenNumber()withK/M/Babbreviations and apply it to Tokens card, model legend and donut center.Testing
node --checkonsrc/utils/usageStats.js,src/server/index.js,src/server/handlers/common/retry.js,src/server/handlers/openai.js,src/server/handlers/claude.js,src/server/handlers/gemini.js,src/server/handlers/geminicli.jsandpublic/js/monitor.js, which completed without errors.npm run build:linuxto validate packaging, butpkgfailed to fetch Node base binaries/source (remote403 Forbidden), which is an environment/remote-cache issue unrelated to the code changes.Codex Task